import { Entity, PrimaryGeneratedColumn, Column, getRepository, createConnection, Connection } from 'typeorm';
import { MyConnection } from './connection';

@Entity('game_config')
export class GameConfig {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({
        name: 'program_one_progress',
        type: 'int'
    })
    programOneProgress: number;

    @Column({
        name: 'program_two_progress',
        type: 'int'
    })
    programTwoProgress: number;

    @Column({
        name: 'program_three_progress',
        type: 'int'
    })
    programThreeProgress: number;

    @Column({
        name: 'program_step',
        type: 'int'
    })
    programStep: number;

    // constructor() { }

    getConfig = async () => {
        try {
            const tableRepository = MyConnection.myConnection.getRepository(GameConfig);
            const info: GameConfig = await tableRepository.findOne({ id: 1 });

            return {
                'program_one_progress': info.programOneProgress,
                'program_two_progress': info.programTwoProgress,
                'program_three_progress': info.programThreeProgress,
                'program_step': info.programStep
            };
        } catch (ex) {
            // console.log(ex);
        }
    }
}
